/*
 * Filename:    OrgReviewDao.java
 * Copyright:   2014 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2014-11-14
 */
package com.paic.mhis.hcpms.evaluation.evaluationOrg.orgReview.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.evaluation.evaluationOrg.evaluationIntegrity.dto.IntegrityEvalDTO;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.orgReview.dto.OrgEvaluationOpinionDTO;
import com.paic.mhis.hcpms.evaluation.evaluationOrg.orgReview.dto.OrgReviewComfirmDTO;
import com.paic.pafa.biz.dao.BaseDAO;

@Component("orgApproveDao")
public class OrgApproveDao extends BaseDAO {

	public List<OrgEvaluationOpinionDTO> getEvaluationOpinionInfoByIsValid(OrgEvaluationOpinionDTO bean) {

		List<OrgEvaluationOpinionDTO> list = (List<OrgEvaluationOpinionDTO>) this._queryForList(
				"orgApprove.getEvaluationOpinionInfoByIsValid", bean);

		return list;

	}

	/**
	 * 
	 * @param evaluationType
	 * @param evalId
	 * @return
	 */
	public List<IntegrityEvalDTO> loadIntegrityEvalDTOBy(String evaluationType, String evaluationCode) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("evaluationType", evaluationType);
		map.put("evaluationCode", evaluationCode);
		List<IntegrityEvalDTO> list = (List<IntegrityEvalDTO>) this._queryForList("orgApprove.loadIntgrityEvalInfo",
				map);

		return list;

	}

	/**
	 * 根据诚信考评表的id 加载对应的饿考评信息
	 * 
	 * @param evalId
	 * @return
	 */
	public List<OrgReviewComfirmDTO> queryOrgReviewComfirmDTOByEvalId(String evaluationCode) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("evaluationCode", evaluationCode);
		List<OrgReviewComfirmDTO> list = (List<OrgReviewComfirmDTO>) this._queryForList(
				"orgApprove.getEvalMarkUserComfirmList", map);

		return list;
	}

	/**
	 * 获取 诚信考评意见表 对应的实体
	 * 
	 * @param bean
	 * @return
	 */
	public List<OrgEvaluationOpinionDTO> getEvaluatonOpinionDTO(OrgEvaluationOpinionDTO bean) {

		List<OrgEvaluationOpinionDTO> list = (List<OrgEvaluationOpinionDTO>) this._queryForList(
				"orgApprove.getEvaluationOpinionInfo", bean);

		return list;

	}

	/**
	 * 保存 诚信考评意见表
	 * 
	 * @param bean
	 */
	public void insertOrgEvaluationOpinionDTO(OrgEvaluationOpinionDTO bean) {
		this._insert("orgApprove.insertEvaluationOpinionInfo", bean);
	}

	/**
	 * 更新 诚信考评意见表
	 * 
	 * @param bean
	 */
	public void updateOrgEvaluationOpinionDTO(OrgEvaluationOpinionDTO bean) {
		this._update("orgApprove.updateEvaluationOpinionInfo", bean);
	}

	/**
	 * 根据诚信子表id及状态查询意见是否存在
	 * 
	 * @param bean
	 */
	public String queryOrgEvaluationOpinion(OrgEvaluationOpinionDTO bean) {
		return this._getString("orgApprove.queryOrgEvaluationOpinion", bean);
	}

	public long getEvalInfoRecordById(String evaluationCode) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("evaluationCode", evaluationCode);
		long count = this._queryForCount("orgApprove.getEvaluationChildRecord", map);

		return count;
	}

	public long getEvaluationOpinionRecord(String evaluationCode, String opinion, String taskStatus, String isValid) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("evaluationCode", evaluationCode);
		map.put("taskStatus", taskStatus);
		map.put("opinion", opinion);
		map.put("isValid", isValid);
		long count = this._queryForCount("orgApprove.getEvaluationOpinionRecord", map);
		return count;
	}

	public long getEvaluationOpinionCountByEvaluationCode(String evaluationCode, String opinion, String taskStatus,
			String isRevoke, String isValid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("evaluationCode", evaluationCode);
		map.put("taskStatus", taskStatus);
		map.put("opinion", opinion);
		map.put("isRevoke", isRevoke);
		map.put("isValid", isValid);
		long count = this._queryForCount("orgApprove.getEvaluationOpinionRecord", map);
		return count;
	}

	/**
	 * 机构 审批 撤销
	 * 
	 * @param map
	 */
	public void cancelMedialIntegrityApprove(Map<String, Object> map) {
		this._update("orgApprove.cancelMedialIntegrityApprove", map);
	}

	/**
	 * @return status
	 */
	public int isCanCancel(Map<String, Object> map) {
		return this._getInt("orgApprove.isCanCancel", map);
	}

	/**
	 * 查询意见表是否有被审批操作过的数据
	 * 
	 * @param map
	 * @return
	 */
	public int opinionCount(Map<String, Object> map) {
		return this._getInt("orgApprove.opinionCount", map);
	}

	/*
	 * 重置审核意见 childId :考评子表id
	 */
	public void reSetEvalOpinion(String evaluationCode, String processStatus, String isValid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("evaluationCode", evaluationCode);
		map.put("processStatus", processStatus);
		map.put("isValid", isValid);
		this._update("orgApprove.reSetEvalOpinion", map);
	}
}
